var a = [1,8,3,41,23,414,4124,121,2,31]

a.sort(compare)
// compare 比较函数
function compare(a,b){
  return a - b
}
console.log(a)
//[1, 2, 3, 8, 23, 31, 41, 121, 414, 4124]

function compare1(a,b){
  return b - a
}

a.sort(compare1)
console.log(a)
//[4124, 414, 121, 41, 31, 23, 8, 3, 2, 1]


a.sort(compare)
console.log(a)
const reversed = a.reverse(); //反转数组 并返回一个新数组
console.log(a == reversed )
console.log(a === reversed )
console.log(reversed )

// https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed

const arrayLike = {
  length: 3,
  unrelated: "foo",
  2: 4,
};
console.log(Array.prototype.reverse.call(arrayLike));
console.log(arrayLike)
console.log(arrayLike instanceof Array) // false

console.log([1, , 3].reverse()); 